﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using snat.model;
using snat.algorithms.network.TFIDF;

namespace snat.algorithms.node.TFIDF {

    public class TFIDFNode<T> : ClusterNode, IAlgorithm where T : Document {

        public static HashSet<int> MessagesAddedToTerms = new HashSet<int>();
        public static Dictionary<String, Term> Terms = new Dictionary<String, Term>();
       // protected List<T> Documents { get { return ReceivedDocuments.Union(SentDocuments).ToList(); } }
        public int DocumentCount {
            get {
                return ReceivedDocuments.Count + SentDocuments.Count;
            }
        }
        public List<T> ReceivedDocuments = new List<T>();
        public List<T> SentDocuments = new List<T>();

        public TFIDFNode(int _id, string _name, int initialCluster = 0)
            : base(_id, _name, initialCluster) { }

        public virtual void OnMessageSend(Message m, BaseNode n) { }
        public virtual void OnMessageReceive(Message m, BaseNode n) { }
        public virtual void NetworkMessageEveryone(Message m) { }
        public virtual void NetworkMessageOnce(Message m) { }

        private static bool registered = false;

        public virtual void Register() {
            this.MessageSend += OnMessageSend;
            this.MessageRecieve += OnMessageReceive;
            NetworkModel.Instance.MessageProcessed += NetworkMessageEveryone;
            if (!registered) {
                NetworkModel.Instance.MessageProcessed += NetworkMessageOnce;
                registered = true;
            }
        }

        public virtual void DeRegister() {
            this.MessageSend -= OnMessageSend;
            this.MessageRecieve -= OnMessageReceive;
            NetworkModel.Instance.MessageProcessed -= NetworkMessageEveryone;
            if (registered) {
                NetworkModel.Instance.MessageProcessed -= NetworkMessageOnce;
                registered = false;
            }
        }



    }
}
